<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tab切换</title>
    <style>
    .box {
      width: 800px;
      margin: 20px auto;
    }

    .tab-title {
      font-size: 20px;
      font-weight: bold;
      display: inline-block;
    }

    .box2 {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .tab-btn {
      color: #666;
      margin: 0 15px;
      cursor: pointer;
      padding-bottom: 2px;

    }

    .tab-btn.active {
      color: red;
      font-weight: bold;
      border-bottom: 2px solid red;
    }

    .tab-img {
      margin-top: 10px;
      width: 100%;
      display: none;
    }

    .tab-img.show {
      display: block;
    }
    </style>
</head>
<body>
    <div class="box">
    <div class="box2">
      <div class="tab-title">每日特价</div>
      <div class="box3">
        <span class="tab-btn active" onclick="Tab(0)">精选</span>
        <span class="tab-btn" onclick="Tab(1)">美食</span>
        <span class="tab-btn" onclick="Tab(2)">百货</span>
        <span class="tab-btn" onclick="Tab(3)">个护</span>
        <span class="tab-btn" onclick="Tab(4)">预告</span>
      </div>
    </div>
    <img class="tab-img show" src="./images/course01.png" alt="">
    <img class="tab-img" src="./images/course02.png" alt="">
    <img class="tab-img" src="./images/course03.png" alt="">
    <img class="tab-img" src="./images/course04.png" alt="">
    <img class="tab-img" src="./images/course05.png" alt="">
  </div>

  <script>
    function Tab(num) {
      const btn = document.querySelectorAll('.tab-btn');
      for (let i = 0; i < btn.length; i++) {
        btn[i].classList.remove('active');
      }
      event.target.classList.add('active');
      const img = document.querySelectorAll('.tab-img');
      for (let i = 0; i < img.length; i++) {
        img[i].classList.remove('show');
      }
      img[num].classList.add('show');
    }
  </script>
</body>
</html>